import 'package:flutter/material.dart';

import '../../common/models/common_meal_model.dart';

class YSHFavorProvider extends ChangeNotifier {
  // 1.定义要分享的数据
  List<YSHCommonMealModel> _favorList = [];
  // 2.重写get方法
  List<YSHCommonMealModel> get favorList {
    return _favorList;
  }
  // 添加收藏
  void addFavorMeal(YSHCommonMealModel mealModel) {
    _favorList.add(mealModel);
    notifyListeners();
  }
  // 取消收藏
  void removeFavorMeal(YSHCommonMealModel mealModel) {
    _favorList.remove(mealModel);
    notifyListeners();
  }
  // 判断是否收藏
  bool isFavorMeal(YSHCommonMealModel mealModel) {
    return _favorList.contains(mealModel);
  }

  void handleFavorMeal(YSHCommonMealModel mealModel) {
    if (!isFavorMeal(mealModel)) {
      addFavorMeal(mealModel);
    } else {
      removeFavorMeal(mealModel);
    }
  }

}